package com.clown.smsdao.coursemanage.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.clown.smsbase.Domain.BaseEntity;
import com.clown.smsdao.studentmanage.domain.Student;
import com.clown.smsdao.teachermanage.domain.Teacher;

import javax.persistence.*;
import java.util.List;

@Entity
public class Course extends BaseEntity<Long> {
    //继承BaseEntity四个基础公共字段
    @Column
    private String name;

    //课程与教师之间的多对一
    @JsonIgnoreProperties("courses")
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "teacher_id")
    private Teacher teacher;
    @JsonIgnoreProperties("courses")
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "courseKind_id")
    private CourseKind courseKind;

    @JsonIgnoreProperties(value = "courseList",allowSetters = true)
    @ManyToMany
    @JoinTable(name = "select_course",joinColumns = @JoinColumn(name = "student_id"),inverseJoinColumns = @JoinColumn(name = "course_id"))
    private List<Student> studentList;
    //学分字段
    @Column
    private Double credit;
    //课程人数
    @Column
    private Integer number;
    //剩余人数
    @Column
    private Integer remaining;
    //上课时间
    @Column
    private String time;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Teacher getTeacher() {
        return teacher;
    }

    public void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }

    public CourseKind getCourseKind() {
        return courseKind;
    }

    public void setCourseKind(CourseKind courseKind) {
        this.courseKind = courseKind;
    }

    public List<Student> getStudentList() {
        return studentList;
    }

    public void setStudentList(List<Student> studentList) {
        this.studentList = studentList;
    }

    public Double getCredit() {
        return credit;
    }

    public void setCredit(Double credit) {
        this.credit = credit;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public Integer getRemaining() {
        return remaining;
    }

    public void setRemaining(Integer remaining) {
        this.remaining = remaining;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    @Override
    public String toString() {
        return "Course{" +
                "name='" + name + '\'' +
                ", credit=" + credit +
                ", number=" + number +
                ", remaining=" + remaining +
                '}';
    }
}
